package com.cqjtu.education.config;

import cn.dev33.satoken.interceptor.SaRouteInterceptor;
import com.cqjtu.education.utils.SaTokenInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;

import java.util.List;

/**
 * @Author: 冉鹏
 * @Date: 2022/4/9 19:24
 */

@EnableWebMvc   //springboot版本过高添加注解 ≥2.6.x
@Configuration
public class SaTokenConfig implements WebMvcConfigurer {

    @Resource
    private SaTokenInterceptor saTokenInterceptor;

    // 注册拦截器
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        List<String> list = new ArrayList<>();
        list.add("/user/login");
        list.add("/user/register");
        list.add("/user/resetPassword");
        list.add("/user/generate");
        list.add("/user/verification");
        list.add("/doc.html/**");
        list.add("/webjars/**");
        list.add("/swagger-ui.html/**");
        list.add("/swagger-resources/**");
        list.add("/v2/api-docs/**");
        list.add("/favicon.ico");
        list.add("/**/error");
        // 注册Sa-Token的路由拦截器  new SaRouteInterceptor()
        registry.addInterceptor(saTokenInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns(list);
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("swagger-ui.html")
                .addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("doc.html")
                .addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**").
                addResourceLocations("classpath:/META-INF/resources/webjars/");
        registry.addResourceHandler("favicon.ico")
                .addResourceLocations("classpath:/static/");
//        registry.addResourceHandler("/**")
//                .addResourceLocations("classpath:/static/")
//                .addResourceLocations("classpath:/META-INF/resources/");
    }
}
